package com.xianyun.book.command;

import com.alibaba.cola.catchlog.CatchAndLog;
import com.alibaba.cola.dto.Response;
import com.xianyun.book.domain.book.Book;
import com.xianyun.book.domain.book.BookStatus;
import com.xianyun.book.domain.gateway.BookGateway;
import com.xianyun.book.dto.BookUpdateCmd;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @author ytt
 */
@Component
@CatchAndLog
public class BookUpdateCmdExe {
    @Resource
    private BookGateway bookGateway;

    public Response execute(BookUpdateCmd cmd){
        Book saleBook =  bookGateway.saveOrQueryBookByIsbn(cmd.getIsbn());
        saleBook.setDesc(cmd.getBookDesc());
        saleBook.setPrice(cmd.getOriginalPrice());
        saleBook.setNewTime(cmd.getNewDate());
        saleBook.setBookStatus(BookStatus.getStatusByNumber(cmd.getBookStatus()));
        bookGateway.updateBook(saleBook);
        return Response.buildSuccess();
    }
}
